class Api::StoreDepartmentsController < Api::BaseController
  before_action :login_required, :set_store
  before_action :set_department, only: [:unuse, :show, :update]
  def create
    @store_department = @store.departments.new(name: params[:name])
    if @store_department.save
      render json: {status: true, department: @store_department}
    else
      render json: {status: false, message: @store_department.errors.full_messages.first}
    end
  end

  def unuse
    @department.unuse!
    render json: {status: true}
  end

  def show
    respond_with @department, location: nil
  end

  def update
    @department.update(name: params[:name])
    render json: {status: true}
  end

  private
  def set_store
    @store ||= current_store
  end

  def set_department
    @department = @store.departments.find(params[:id])
  end
end
